//
//  SEGHotLineCardTableViewCell.m
//  Commom
//
//  Created by 梁学彰 on 2020/3/16.
//

#import "SEGHotLineCardTableViewCell.h"
#import "CommomHeader.h"

@interface SEGHotLineCardTableViewCell ()
@property (nonatomic, strong) UIView *contentWhiteView;
@property (nonatomic, strong) UIButton *callBtn;
@end

@implementation SEGHotLineCardTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentWhiteView = [UIView new];
    self.contentWhiteView.backgroundColor = kColor_W;
    [self.contentView addSubview:self.contentWhiteView];
    
    [self.contentWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.left.equalTo(self.contentView).offset(20);
        make.right.equalTo(self.contentView).offset(-20);
    }];
    
    self.contentWhiteView.layer.shadowColor = kColor_L2.CGColor;
    self.contentWhiteView.layer.shadowOpacity = 0.36f;
    self.contentWhiteView.layer.cornerRadius = 5;
    self.contentWhiteView.layer.shadowOffset = CGSizeMake(0,0);
    
    self.titleLabel = [UILabel new];
    self.titleLabel.text = @"#333333";
    self.titleLabel.font = [kFont_16 fontWithBold];
    self.titleLabel.textColor = kColor_1;
    [self.contentWhiteView addSubview:self.titleLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentWhiteView).offset(19);
        make.height.mas_equalTo(18);
        make.left.equalTo(self.contentWhiteView).offset(20);
        make.width.mas_lessThanOrEqualTo(LYScreenWidth() - 80 - 40 - 60);
    }];
    
    self.telLabel = [UILabel new];
    self.telLabel.font = kFont_13 ;
    self.telLabel.text = @"#333333";
    self.telLabel.textColor = kColor_3;
    [self.contentWhiteView addSubview:self.telLabel];
    
    [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentWhiteView).offset(-17);
        make.height.mas_equalTo(15);
        make.left.equalTo(self.contentWhiteView).offset(20);
        make.width.mas_lessThanOrEqualTo(LYScreenWidth() - 80 - 60);
    }];
    
    self.callBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.callBtn setImage:[UIImage imageNamed:SEGPicName(@"icon_btn_hotline_call")] forState:UIControlStateNormal];
    [self.contentWhiteView addSubview:self.callBtn];
    
    [self.callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentWhiteView);
        make.right.equalTo(self.contentWhiteView).offset(-22);
        make.height.width.mas_equalTo(36);
    }];
    
    [self.callBtn addTarget:self action:@selector(callAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)callAction {
    if (self.telLabel.text.length <= 0) {
        //只有管家会有这种情况
        [SEGAlertView showTmepMessageWithMessage:@"暂未更新管家联系方式"];
        return;
    }
    SEGNewAlertView *alertView = [[SEGNewAlertView alloc] init];
    [alertView showWithAlertTitle:nil text:[NSString stringWithFormat:@"%@",self.telLabel.text] buttonTitlesArray:@[@"取消",@"呼叫"] actionBlock:^(NSInteger btnIndex) {
        if (btnIndex == 1) {
            if (@available(iOS 8.0, *)) {
                    NSString *str = [NSString stringWithFormat:@"telprompt://%@",self.telLabel.text];
                if (@available(iOS 10.0, *)) {
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil];
                    } else {
                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
                }
            }
        }
    }];
}

@end
